//As the call stack is unwound, the destructor for the constructed local 
//object are invoked
//
//Resource acquisition is initialization
#include <iostream>
#include <exception>
using namespace std;

class myexception : public exception {
public:
  const char* what() const throw(){return "myexception";}
};

class A {
  int aa;
public:
  A(){cout<<"A()"<<endl;}
  ~A(){cout<<"~A()"<<endl;}
};

void foo()
{
  try{ 
  A a;
  A* ap = new A;//not automatically destructed
  throw myexception();
  }
  catch(...) {
    throw;
  }
}

int main()
{
  try{
    foo();
  }
  catch(exception& ex) {
    cout<<ex.what()<<endl;
  }
  cout<<"out of catch in main()"<<endl;
  return 0;
}
    
